<?php
namespace app\app\model;
use think\Model;
use think\Session;
class Talk extends Model
{
    public  function createTalk($comment)
    {
        $talk = new Talk;
        $talk->commentName = $comment['commentName'];
        $talk->commentTime = time();
        $talk->commentContent = $comment['commentContent'];
        $talk->user_id = $comment['user_id'];
        $talk->user_role = Session::get('role','app');
        $talk->save();
        $talk_id =$talk->id;
        return $talk_id;
    }
    public function saveLikes($data)
    {
        $talk = new Talk;
        $num_org = db('talk')->where('id',$data['id'])->value('likes');
        if ($num_org == '0' && $data['num'] == '-1'){
            return false;
        }
        $num = $num_org + intval($data['num']);
        $list = [
            'likes' => $num
        ];
        $result = $talk->save($list,['id' => $data['id']]);
        return $result;
    }
}